import { Card, Form, Button, Checkbox, Input } from 'antd'
import logo from '../../assets/logo.png'
import styles from './index.module.scss'
import React from 'react'

export default function Login () {
  const onFinish = (value) => {
    console.log(value)
  }
  return (
    <div className={styles.root}>
      <Card className="login-container">
        {/* 图片 */}
        <img className="login-logo" src={logo} alt="" />
        {/* 表单 */}
        <Form
          autoComplete="off"
          size="large"
          validateTrigger={['onChange', 'onBlur']}
          // 设置表单默认值initialValues
          initialValues={{
            mobile: '13612345678',
            code: '678910',
            agree: true
          }}
          onFinish={onFinish}>
          <Form.Item
            name="mobile"
            rules={[
              { require: true, message: '手机号必填' },
              {
                pattern: /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/,
                message: '手机号格式不正确'
              }
            ]}>
            <Input placeholder="请输入手机号" />
          </Form.Item>
          <Form.Item
            name="code"
            rules={[
              { require: true, message: '验证码必填' },
              {
                pattern: /^\d{6}$/,
                message: '验证码格式不正确'
              }
            ]}>
            <Input placeholder="请输入验证码" />
          </Form.Item>

          <Form.Item
            name="agree"
            valuePropName="checked"
            rules={[
              {
                validator (rule, value) {
                  if (value) {
                    return Promise.resolve()
                  } else {
                    return Promise.reject(new Error('请阅读并同意协议'))
                  }
                }
              }
            ]}>
            <Checkbox>我已阅读并同意[隐私条款]和[用户协议]</Checkbox>
          </Form.Item>

          <Form.Item>
            <Button type="primary" htmlType="submit" block>
              登录
            </Button>
          </Form.Item>
        </Form>
      </Card>
    </div>
  )
}
